﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListTheCity.ascx.cs" Inherits="Modules_ListTheCity" %>
<%@ Import Namespace="SMS.Helper" %>

<div id="box">
    <h3>DANH SÁCH THÀNH PHỐ</h3><br />

    <div align="center"><asp:Label ID="lblError" runat="server" /></div><br />

    <fieldset id="personal">
        <label>Tên thành phố : </label>
        <asp:TextBox ID="txtCityName" runat="server" Width="250px" />&nbsp;<asp:Button ID="btnSearch" runat="server" Text="Tìm" Width="60px" OnClick="btnSearch_Click" CssClass="btn" /><br />
    </fieldset><br />

    <div align="center"><asp:Button ID="lnkDelete" runat="server" OnClick="lnkDelete_Click" Text="Xóa" CssClass="btn" /></div>

    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td align="center">
            <asp:GridView ID="grvCity" runat="server" 
                Width="98%" DataKeyNames="CityID" AutoGenerateColumns="False" 
                AllowPaging="True" PageSize="30" AllowSorting="True" CellPadding="4" ForeColor="#333333" ShowFooter="true"
                PagerStyle-HorizontalAlign="Center" EmptyDataText="Không có bản ghi nào."
                PagerSettings-NextPageText="Next" PagerSettings-PreviousPageText="Prev" PagerStyle-CssClass="pagerText" 
                OnRowCancelingEdit="grvCity_RowCancelingEdit" OnPageIndexChanging="grvCity_PageIndexChanging"
                OnRowCommand="grvCity_RowCommand" OnRowDeleting="grvCity_RowDeleting" 
                OnRowEditing="grvCity_RowEditing" OnRowUpdating="grvCity_RowUpdating">
                <PagerSettings PageButtonCount="10" />
                <FooterStyle BackColor="#1EB5DD" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#1EB5DD" ForeColor="White" />
                <RowStyle Height="30px" ForeColor="#333333" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#eeecdf" Font-Bold="True" ForeColor="#a4363a" />
                <AlternatingRowStyle BackColor="#f7f6f0" Height="30px" ForeColor="#284775" />
                <Columns>
                    <asp:TemplateField>
                        <HeaderStyle HorizontalAlign="Center" Width="40px" />
                        <HeaderTemplate>
                            <input type="checkbox" id="cbxHeader" runat="server" value="" onclick="MarkAll()" style="border:0px" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <input type="checkbox" id="cbxItem" runat="server" value='<%# Eval("CountryID") %>' onclick="MarkOne()" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Stt">
                        <ItemTemplate><%# Container.DataItemIndex + 1 %></ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Tên thành phố">
                        <ItemTemplate><%# Eval("CityName")%></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtEditCityName" runat="server" Width="100px" Text='<%#Eval("CityName")%>' />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtInsCityName" runat="server" Width="100px" />
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Mã thành phố">
                        <ItemTemplate><%# Eval("CityName")%></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtEditCityCode" runat="server" Width="100px" Text='<%#Eval("CityCode")%>' />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtInsCityCode" runat="server" Width="100px" />
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Quốc gia">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlCountry" runat="server" DataTextField="CountryName" DataValueField="CountryID" />
                        </ItemTemplate>
                	    <EditItemTemplate>
                            <asp:DropDownList ID="ddlEditCountry" runat="server" DataTextField="CountryName" DataValueField="CountryID" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:DropDownList ID="ddlInsCountry" runat="server" DataTextField="CountryName" DataValueField="CountryID" />
                        </FooterTemplate>
                    </asp:TemplateField>   
        		    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Button ID="lbtnEdit" runat="server" CausesValidation="false" CommandName="Edit" Text="Sửa" />&nbsp;
                            <asp:Button ID="lbtnDelete" runat="server" CausesValidation="false" CommandName="Delete" Text="Xoá" />
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:Button ID="lbtnInsert" runat="server" CommandName="Insert" Text="Thêm mới" />
                        </FooterTemplate>
                        <EditItemTemplate>
                            <asp:Button ID="lbtnUpdate" runat="server" CausesValidation="false" CommandName="Update" Text="Cập nhật" />
                            <asp:Button ID="lbtnCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Hủy bỏ" />
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </td>
    </tr>
    </table><br />

    <div align="center"><asp:Button ID="lnkDeleteBottom" runat="server" OnClick="lnkDelete_Click" Text="Xóa" CssClass="btn" /></div>
</div>
<script language="javascript" type="text/javascript">
    var grid = document.getElementById('<%= this.grvCity.ClientID %>');
	
    function MarkAll()
    {
	    var isChecked = document.getElementById('<%= (this.grvCity.HeaderRow == null) ? "" : this.grvCity.HeaderRow.Cells[0].Controls[1].ClientID %>').checked;
	    for (i = 1; i < grid.rows.length; i++)
	    {
		    grid.rows[i].cells[0].children[0].checked = isChecked;
	    }
    }
    function MarkOne()
    {
	    var cbx = document.getElementById('<%= (this.grvCity.HeaderRow == null) ? "" : this.grvCity.HeaderRow.Cells[0].Controls[1].ClientID %>');
	    cbx.checked = false;
		
	    for (i = 1; i < grid.rows.length; i++)
	    {
		    if (!grid.rows[i].cells[0].children[0].checked) return;
	    }
	    cbx.checked = true;
    }
	
    function CheckSelect()
    {
	    for (i = 1; i < grid.rows.length; i++)
	    {
		    if (grid.rows[i].cells[0].children[0].checked) return true;
	    }
	    alert('Không có bản ghi nào được đánh dấu');
	    return false;
    }
</script>